/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"B7D573CA-8463-415F-B725-CC88544FC2EF"}
 */
var fCadena = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"3E8B102B-B3AF-49DB-8AB4-927E4C63FCAD"}
 */
var fError = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"90165176-AE40-4969-AC27-60702581B454"}
 */
var fUser = null;

/**
 * @type {String}
 *
 * @properties={typeid:35,uuid:"CB82392D-F981-4348-B6A6-EE7AC773972F"}
 */
var fPass = null;

/**
 *
 * @properties={typeid:24,uuid:"91596DE5-C57A-48D6-AA81-8A8447F7163A"}
 * @AllowToRunInFind
 */
function Entrar()
{
	var ok = security.authenticate("hoteleria_admin_auth","autenticar",[fCadena,fUser,fPass]) 
	if (ok == 1)
	{
		var $sql 	= 'SELECT usuario_id, u.cadena_id FROM usuarios "u" JOIN cadenas "c" ON c.cadena_id = u.cadena_id WHERE usuario = ? AND descripcion_login = ?'
		var $args 	= [fUser, fCadena]
		var $ds 	= databaseManager.getDataSetByQuery('hoteleria',$sql,$args,-1) 
		
		if ($ds.getMaxRowIndex() == 1)
		{
			globals.gCadena = $ds.getValue(1,2)
			globals.gUsuarioId = $ds.getValue(1,1)
		}
		return true
	}
	else
	{
		switch (ok)
		{
			case 2:
			{
				//globals.DIALOGS.showErrorDialog('Error','Usuario incorrecto o permiso denegado','OK')
				fError = i18n.getI18NMessage('hoteleria.login.error.permiso_denegado')
				break;
			}
			case 3:
			{
				//globals.DIALOGS.showErrorDialog('Error','*Contraseña incorrecta','OK')
				fError = i18n.getI18NMessage('hoteleria.login.error.password')
				break;
			}
			case 4:
			{
				//globals.DIALOGS.showErrorDialog('Error','Usuario no existe','OK')
				fError = i18n.getI18NMessage('hoteleria.login.error.user')
				break;
			}
		}
	return false
	}
}

/**
 * Callback method for when form is shown.
 *
 * @param {Boolean} firstShow form is shown first time after load
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"F26AE360-5FF4-4A7A-9DC3-FFBF60160CFB"}
 */
function onShow(firstShow, event) {
	elements.fCadena.requestFocus()
}

/**
 * Handle hide window.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @returns {Boolean}
 *
 * @properties={typeid:24,uuid:"86CB153E-E886-4E6A-987C-8FAE0CCB9202"}
 */
function onHide(event) {
	if (security.getUserName() == null)
		return false
		
	return true
}

/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"3DDBE977-53EF-4E3B-B890-8E2D6C27B899"}
 */
function salir(event) {
	application.exit()
}

/**
 * Handle focus gained event of the element.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"09892217-BD45-45B9-A225-05359B672DB4"}
 */
function borrarMensaje(event) {
	fError = null
}
